﻿using System.Text;

namespace Server
{
    internal class SimpleServer
    {
        Server server;
        ClientInfo client;

        public delegate void RecievingDelegate(ClientInfo ci, Server s, string msg);

        public event RecievingDelegate OnRecieving;

        public void Start(int port)
        {
            server = new Server(port, new ClientEvent(ClientConnect));
            server.DefaultEncryptionType = EncryptionType.ServerRSAClientKey;
        }

        bool ClientConnect(Server serv, ClientInfo new_client)
        {
            new_client.Delimiter = "\n";
            new_client.OnRead += new ConnectionRead(ReadMessage);

            return true; // allow this connection
        }

        void ReadMessage(ClientInfo ci, string text)
        {
            OnRecieving(ci, server, text);
        }
    }
}